package com.itguigu.process.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itguigu.auth.service.SysUserService;
import com.itguigu.model.process.ProcessRecord;
import com.itguigu.model.system.SysUser;
import com.itguigu.process.mapper.OaProcessRecordMapper;
import com.itguigu.process.service.ProcessRecordService;
import com.itguigu.security.custom.LoginUserInfoHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 *  记录审批 服务实现类
 */
@Service
public class ProcessRecordServiceImpl extends ServiceImpl<OaProcessRecordMapper , ProcessRecord> implements ProcessRecordService {

    @Resource
    private SysUserService sysUserService;

    @Resource
    private OaProcessRecordMapper processRecordMapper;

    /**
     * 根据流程id  , 状态 , 描述 添加 流程提交记录
     * @param processid  : 流程id
     * @param status  : 状态
     * @param description  : 描述
     */
    @Override
    public void record(Long processid, Integer status, String description) {
        // 根据 用户id 获取 当前用户信息
        Long userId = LoginUserInfoHelper.getUserId();
        SysUser sysUser = sysUserService.getById(userId);

        // 将 提交审批记录 由该用户 保存到数据库当中
        ProcessRecord processRecord = new ProcessRecord();
        processRecord.setProcessId(processid);
        processRecord.setDescription(description);
        processRecord.setStatus(status);
        processRecord.setOperateUserId(sysUser.getId());
        processRecord.setOperateUser(sysUser.getName());
        processRecordMapper.insert(processRecord);
    }
}
